Skip to content

feat: add rh-keycloak wrapper chart with short-lived ExternalSecret lifecycle#137

Open
minmzzhang wants to merge 1 commit into
validatedpatterns:mainfrom
minmzzhang:one-shot-keycloak-users
Open

feat: add rh-keycloak wrapper chart with short-lived ExternalSecret lifecycle#137
minmzzhang wants to merge 1 commit into
validatedpatterns:mainfrom
minmzzhang:one-shot-keycloak-users

Conversation

@minmzzhang

@minmzzhang minmzzhang commented May 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add a wrapper chart (charts/rh-keycloak) that consumes the rhbk chart as a dependency and configures the keycloakUsers ExternalSecret with a short-lived ArgoCD hook lifecycle
  • Switch values-hub.yaml from the remote rhbk chart to the local rh-keycloak wrapper chart path
  • A simplified PostSync Job deletes the keycloak-users Secret after realm import for security hygiene

How it works

The keycloakUsers ExternalSecret is annotated as an ArgoCD Sync hook with HookSucceeded delete policy and ESO resource policies:

  1. ArgoCD creates the ExternalSecret during sync (hook: Sync)
  2. ESO fetches user passwords from Vault and creates the keycloak-users Secret (creationPolicy: Orphan)
  3. Keycloak realm import reads the Secret and stores credentials in PostgreSQL
  4. ArgoCD deletes the ExternalSecret after it reaches Ready (HookSucceeded + PrunePropagationPolicy=orphan)
  5. The Secret persists (deletionPolicy: Retain) — ESO can no longer overwrite it
  6. A PostSync Job deletes the keycloak-users Secret (no longer needed, contains initial passwords)

A conditional NetworkPolicy for the cleanup Job is included for environments with default-deny policies.

Dependencies

  • Requires rhbk-chart >= 0.0.12 — lifecycle management for ExternalSecrets (tagged and published)

@minmzzhang minmzzhang requested review from mlorenzofr, p-rog and sabre1041 and removed request for sabre1041 May 21, 2026 22:09

@mlorenzofr mlorenzofr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to rebase after merge #135

  1. Add extraValueFiles... to values-hub.yaml
  2. Add rhbk: to the beginning of overrides/values-keycloak-network-policy.yaml and fix the indentation

Apart from that, everything else has worked correctly

@minmzzhang minmzzhang force-pushed the one-shot-keycloak-users branch from 64360bb to 2d728b4 Compare May 25, 2026 18:35
@minmzzhang

Copy link
Copy Markdown
Collaborator Author

We need to rebase after merge #135

  1. Add extraValueFiles... to values-hub.yaml
  2. Add rhbk: to the beginning of overrides/values-keycloak-network-policy.yaml and fix the indentation

Apart from that, everything else has worked correctly

rebased the latest main and force pushed.

@mlorenzofr

Copy link
Copy Markdown
Collaborator

Depends on validatedpatterns/rhbk-chart#15

@mlorenzofr mlorenzofr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and everything is fine

Once we have the merged validatedpatterns/rhbk-chart#15, we could also merge this PR

LGTM

@p-rog

p-rog commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

@minmzzhang I have a feeling that this update will break applied Keycloak network policies: #135
Right now we assume that rh-keycloak app is deployed from external chart: rhbk, and we use extraValueFiles for Keycloak network policies. Let me test it.

@p-rog

p-rog commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

@minmzzhang I have a feeling that this update will break applied Keycloak network policies: #135
Right now we assume that rh-keycloak app is deployed from external chart: rhbk, and we use extraValueFiles for Keycloak network policies. Let me test it.

Never mind, I see that you covered already compatibility. Great job!
LGTM

@p-rog p-rog left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, only address the merge conflicts.

@minmzzhang minmzzhang force-pushed the one-shot-keycloak-users branch 2 times, most recently from 00553bc to 163be93 Compare June 12, 2026 18:56
@minmzzhang minmzzhang changed the title feat: add rh-keycloak wrapper chart with PostSync cleanup for one-shot ExternalSecrets feat: add rh-keycloak wrapper chart with short-lived ExternalSecret lifecycle Jun 12, 2026
@minmzzhang minmzzhang force-pushed the one-shot-keycloak-users branch 2 times, most recently from a72a14d to a01c90c Compare June 12, 2026 19:04
…ifecycle

Add a wrapper chart (charts/rh-keycloak) that consumes the rhbk chart
as a dependency and configures keycloakUsers ExternalSecret with a
short-lived ArgoCD hook lifecycle:

- ExternalSecret annotated as a Sync hook, deleted by HookSucceeded
- creationPolicy: Orphan + deletionPolicy: Retain ensures the Secret
  survives ExternalSecret deletion
- A simplified PostSync Job deletes the keycloak-users Secret by name
  after Keycloak realm import consumes it (security hygiene)
- Conditional NetworkPolicy for the cleanup Job when default-deny is enabled

Switch values-hub.yaml from the remote rhbk chart to the local
rh-keycloak wrapper chart path.

Requires rhbk-chart >= 0.0.12 (lifecycle management for ExternalSecrets).

Signed-off-by: Min Zhang <minzhang@redhat.com>
@minmzzhang minmzzhang force-pushed the one-shot-keycloak-users branch from a01c90c to af62d3e Compare June 12, 2026 20:16

@sabre1041 sabre1041 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Works like a charm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants